<template lang='pug'>
  .smart-link-wrap
    button.btn(
      type="button"
      :class="['btn-outline-' + styleType, 'btn-' + size, {'btn-block': block}, ...buttonClass]"
      :style="buttonStyle"
      :disabled="disabled"
      @click="handleClick")
      span(v-if="icon")
        i(:class="['iconfont', 'icon-' + icon]")
      | {{label}}
    SmartDialog(
      v-model="dialogVisible"
      title="新页面"
      size="md")
</template>

<script>
/**
 * @name 链接跳转
 * @author linmn
 */
import SmartDialog from '@/components/SmartDialog'
export default {
  name: 'SmartLink',
  components: {
    SmartDialog
  },
  props: {
    size: {
      type: String,
      default: 'md'
    }, // 按钮大小，有lg/md/sm/xs四种规格
    icon: String, // 按钮icon
    styleType: {
      type: String,
      default: 'success'
    }, // 按钮类型，有 default|primary|complete|success|danger|warning|info|七种类型
    buttonStyle: {
      type: Object,
      default: () => ({})
    }, // 按钮自定义样式
    buttonClass: {
      type: Array,
      default: () => []
    },
    label: {
      type: String,
      default: '提交'
    }, // 按钮显示文字
    block: {
      type: Boolean,
      default: false
    }, // 按钮是否100%宽度
    disabled: {
      type: Boolean,
      default: false
    }, // 按钮是否可点击
    turnTo: {
      type: String,
      default: ''
    },
    openType: {
      type: String,
      default: 'NEWPAGE' // 打开方式：['NEWPAGE': 新页面', 'INPAGE': '页面内']
    }
  },
  data () {
    return {
      dialogVisible: false
    }
  },
  methods: {
    handleClick () {
      if (!this.openType || !this.turnTo) return
      console.log('this.openType-', this.openType)
      if (this.openType === 'NEWPAGE') {
        // this.$message.warning('暂不支持在页面中打开, 请设置为新页面打开')
        // window.location.href = this.turnTo
        // $route.redirectedFrom 重定向
        this.$router.replace({
          path: this.turnTo,
          meta: {
            keepAlive: true
          }
        })
      } else {
        // this.dialogVisible = true
        this.$message.warning('暂不支持在页面中打开, 请设置为新页面打开')
      }
    }
  }
}
</script>

<style lang='sass' scoped>

</style>
